from django.db import models
from user.models import JobInfo


# Create your models here.

class JobCategories(models.Model):
    name = models.CharField(max_length=100, verbose_name='职位名称')
    pid = models.ForeignKey('self', null=True, blank=True, verbose_name='父级职位id', on_delete=models.CASCADE,
                            related_name='children')

    class Meta:
        db_table = 'job_categories'

    def __str__(self):
        return self.name


# 招聘信息表
class Jobposting(models.Model):
    title = models.CharField(max_length=100, verbose_name='职位名称')
    money = models.CharField(max_length=100, verbose_name='职位薪资')
    type = models.IntegerField(choices=((0, "不限"), (1, "兼职"), (2, "全职")), verbose_name='职位类型', default=0)
    working = models.IntegerField(
        choices=((0, "经验不限"), (1, "在校生"), (2, "应届生"), (3, "1-3年"), (4, "3-5年"), (5, "5年以上")),
        verbose_name='工作经验', default=0)
    education = models.CharField(max_length=100, verbose_name='职位学历', default="不限")
    label = models.CharField(max_length=100, verbose_name='职位标签', default=title)
    description = models.TextField(verbose_name='职位描述', default="暂无")
    city = models.ForeignKey('user.City', verbose_name='职位城市', on_delete=models.CASCADE)
    hr = models.ForeignKey('user.HRInfo', verbose_name='HR', on_delete=models.CASCADE)
    company = models.ForeignKey('user.Company', verbose_name='公司', on_delete=models.CASCADE)
    jobcate = models.ForeignKey('JobCategories', verbose_name='行业第三级分类', on_delete=models.CASCADE)
    browse_number = models.IntegerField(default=0, verbose_name='被浏览数量')
    collect_number = models.IntegerField(default=0, verbose_name='被收藏数量')
    deliver_number = models.IntegerField(default=0, verbose_name='被投递数量')

    class Meta:
        db_table = 'Jobposting'

    def __str__(self):
        return self.title


# 用户游览招聘信息
class BrowseJobposting(models.Model):
    jobposting = models.ForeignKey(Jobposting, verbose_name='职位id', on_delete=models.CASCADE)
    jobinfo = models.ForeignKey(JobInfo, verbose_name='求职者id', on_delete=models.CASCADE)

    class Meta:
        db_table = 'BrowseJobposting'


# 用户收藏招聘信息
class CollectJobposting(models.Model):
    jobposting = models.ForeignKey(Jobposting, verbose_name='职位id', on_delete=models.CASCADE)
    jobinfo = models.ForeignKey(JobInfo, verbose_name='求职者id', on_delete=models.CASCADE)

    class Meta:
        db_table = 'CollectJobposting'


# 用户投递招聘信息
class DeliverJobposting(models.Model):
    jobposting = models.ForeignKey(Jobposting, verbose_name='职位id', on_delete=models.CASCADE,
                                   related_name='deliver_jobposting')
    jobinfo = models.ForeignKey(JobInfo, verbose_name='求职者id', on_delete=models.CASCADE,
                                related_name='delivered_jobs')
    resume_status = models.IntegerField(verbose_name='简历状态',
                                        choices=((0, '未处理'), (1, '处理中'), (2, '处理失败'), (3, '处理成功')),
                                        default=0)
    inter_status = models.IntegerField(verbose_name='初筛状态',
                                       choices=((0, '未处理'), (1, '通过'), (2, '未通过')),
                                       default=0)
    created_at = models.DateTimeField(verbose_name='投递时间', auto_now_add=True)

    class Meta:
        db_table = 'deliverJobposting'


# 问答系统表
class QuestionAnswer(models.Model):
    jobinfo = models.ForeignKey(JobInfo, verbose_name='求职者id', on_delete=models.CASCADE)
    name = models.CharField(max_length=100, verbose_name='名称')

    class Meta:
        db_table = 'QuestionAnswer'


# 问答信息表
class QuestionAnswerInfo(models.Model):
    questionanswer = models.ForeignKey(QuestionAnswer, verbose_name='问题id', on_delete=models.CASCADE)
    question = models.TextField(verbose_name='问题')
    answer = models.TextField(verbose_name='答案')

    class Meta:
        db_table = 'QuestionAnswerInfo'
